package com.longge;

public class CanPlaceFlowers {

    public boolean canPlaceFlowers(int[] flowerbed, int n) {

        int pre = flowerbed[0];
        if (pre == 0 && flowerbed.length == 1) return true;
        for (int i = 1; i < flowerbed.length; i++) {
            if (flowerbed[i] == 0 && pre == 0) {
                if (i + 1 < flowerbed.length && flowerbed[i + 1] == 0) {
                    if (i != 1) {
                        pre = 1;
                    }
                    n--;
                } else if (i + 1 == flowerbed.length) {
                    n--;
                } else if (i == 1) {
                    n--;
                }

            } else {
                pre = flowerbed[i];
            }
        }
        return n <= 0;
    }
}
